package com.lijy.socket;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
import org.junit.Test;

public class SocketTest {
    public static void main(String[] args) throws IOException {
        Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13);
        InputStream inStream = s.getInputStream();
        Scanner in = new Scanner(inStream);
        while (in.hasNextLine()) {
            String line = in.nextLine();
            System.out.println(line);
        }
        in.close();

//        InputStreamReader isr = new InputStreamReader(inStream);
//        BufferedReader br = new BufferedReader(isr);
//        String info;
//        while ((info = br.readLine()) != null) {
//            System.out.println(info);
//        }
//        br.close();
//        isr.close();

        inStream.close();

    }

    @Test
    public void getHost() throws UnknownHostException {
        InetAddress address = InetAddress.getByName("time-A.timefreq.bldrdoc.gov");
        System.out.println(address.getCanonicalHostName());
        System.out.println(address.getHostName());
        System.out.println(address.getHostAddress());
        InetAddress local = InetAddress.getLocalHost();
        System.out.println(local);
    }
}
